import React, { PureComponent,Fragment } from "react";
import { connect } from "dva";
import moment from "moment";
import { Row, Col, Table, Spin, Card } from "antd";

@connect(({ equipment_integrated,global,loading }) => ({
  dictionaries:global.dictionaries,
  tableData: equipment_integrated.log.mainten,
  loading: loading.models.equipment_integrated,
}))

export default class Maintenlog extends PureComponent {
  constructor(props) {
    super(props);
    this.detailInfoId = this.props.match.params.id && this.props.match.params.id!='detail' ? this.props.match.params.id : 0;
    this.state={
      currentPage: 1,
      pageSize: 10,
    }
  }

  componentDidMount() {
    const {currentPage,pageSize} = this.state;
    this.getDataList(pageSize,currentPage)
  }

  getDataList(pageSize,currentPage) {
    const { dispatch } = this.props;
    dispatch({
      type: 'equipment_integrated/fetch_mainten_log',
      payload: {
        devId: this.detailInfoId,
        pageSize,
        currentPage
      },
    });
  }

  // 分页、排序、筛选变化时触发
  handleTableChange = (pagination, filtersArg, sorter) => {
    const { pageSize } = this.state;

    this.setState({
      currentPage:pagination.current
    },()=>{
      this.getDataList(pageSize,pagination.current);
    })

  };


  render() {
    const { tableData,loading,dictionaries } = this.props;

    const repairStatus = dictionaries.repairStatus && dictionaries.repairStatus.length>0
      ? dictionaries.repairStatus.map(item=>item.label)
      :[];

    const columns = [{
      title: '序号',
      dataIndex: 'index',
      render: (text, row, index)=> (
        <span>{index+1}</span>
      ),
    }, {
      title: '保养单的状态',
      dataIndex: 'status',
      render: (text)=> (
        <span>{repairStatus[parseInt(text)-1]}</span>
      ),
    }, {
      title: '保养单号',
      dataIndex: 'taskCode',
    }, {
      title: '起始时间',
      dataIndex: 'beginTime',
      render: (text, row, index) => `${moment(text).format("YYYY-MM-DD HH:mm")} 至 ${moment(row.endTime).format("YYYY-MM-DD HH:mm")}`
    },
    //   {
    //   title: '设备编号',
    //   dataIndex: 'devCode',
    // },{
    //   title: '设备名称',
    //   dataIndex: 'devName',
    // },
      {
      title: '维保单位',
      dataIndex: 'maintenanceName',
    }];

    return (
      <Card bodyStyle={{padding:0}} >
        <Table
          columns={columns}
          dataSource={tableData && tableData.list ? tableData.list : []}
          pagination={tableData && tableData.pagination}
          onChange={this.handleTableChange}
          loading={loading}
          rowKey={"taskId"}
        />
      </Card>

    );
  }
}
